//package com.lill.system.constant;
//
//import java.io.ByteArrayOutputStream;
//import java.io.IOException;
//import java.io.InputStream;
//
//import com.qiniu.storage.BucketManager;
//import okhttp3.OkHttpClient;
//import okhttp3.Request;
//import okhttp3.ResponseBody;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import com.google.gson.Gson;
//import com.qiniu.common.QiniuException;
//import com.qiniu.common.Zone;
//import com.qiniu.http.Response;
//import com.qiniu.storage.Configuration;
//import com.qiniu.storage.UploadManager;
//import com.qiniu.storage.model.DefaultPutRet;
//import com.qiniu.util.Auth;
//
//
//public class QiniuUploadConfig {
//	
//	protected static Logger logger = LoggerFactory.getLogger(QiniuUploadConfig.class);
//	
//	//账号:18211023828@163.com
//	//密码:wode498818209
//	
//    public final static  String domain="http://qiniu.zhonghaiev.com/";
//    public final static  String domainXCJ="http://qiniu.xcj100.com/";
//    //旧
////    private final static String accesskey="yWZqOFrT2o0q5XN0EJo-Jq9OzO_hj-YcIWDKYm5D";
//    //新
//    private final static String accesskey="xw-gj9tFNy0USUh_A6_pB6XwULlXI0a2tRHbDf4x";
//
////    private final static String secretkey="LPSHuTK41waTv4gSGHhtDx3hEIrZL50huGpwhjeM";
//    private final static String secretkey="z1f7AAgvSpcjHixVvxN3Q8kM3rePZde-eNBZlVNC";
//
//    private final static String bucket="zhdd_file";
//
//    public static void main(String[] args) throws Exception{
////        int delete = this.delete("1573788627463");
////        if (delete > -1) {
////            System.err.println("删除成功");
////        }
//    }
//
//    //删除文件
//    public int delete(String url) throws QiniuException{
//        //构造一个带指定Zone对象的配置类
//        Configuration cfg = new Configuration(Zone.zone0());
//        String key = url;
//        Auth auth = Auth.create(accesskey, secretkey);
//        BucketManager bucketManager = new BucketManager(auth, cfg);
//        try {
//            Response delete = bucketManager.delete(bucket, key);
//            System.err.println("删除服务器文件名为=" + url);
//            return delete.statusCode;
//        } catch (QiniuException ex) {
//            //如果遇到异常，说明删除失败
//            ex.printStackTrace();
//            System.err.println(ex.code());
//            System.err.println(ex.response.toString());
//        }
//        return -1;
//    }
//
//    public String uploadImpInputStream(InputStream itm, String key){
//        Configuration cfg = new Configuration(Zone.zone0());
//        //...其他参数参考类注释
//        UploadManager uploadManager = new UploadManager(cfg);
//        String upToken=getUpTokens();
//        try {
//            Response response = uploadManager.put(itm,key,upToken,null, null);
//            //解析上传成功的结果
//            //putRet.key为上传至七牛云文件名称
//            DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
////            System.err.println("上传服务器文件名为=" + key);
//            return putRet.key;
//        } catch (QiniuException ex) {
//        	try {
//                logger.error(ex.response.bodyString());
//            } catch (QiniuException ex2) {
//            	logger.error(ex2.getMessage(),ex2);
//            }
//        }finally{
//        	try {
//				if(null!=itm){
//					itm.close();
//				}
//			} catch (IOException e) {
//				logger.error(e.getMessage(),e);
//			}
//        }
//        return null;
//    }
//
//    public String getUpTokens() {
//        Auth auth = Auth.create(accesskey, secretkey);
//        return auth.uploadToken(bucket);
//    }
//
//    /**
//     * 获取下载文件路径，即：donwloadUrl
//     * @return
//     */
//    public String getDownloadUrl(String targetUrl) {
//        Auth auth = Auth.create(accesskey, secretkey);
//        String downloadUrl = auth.privateDownloadUrl(targetUrl);
//        return downloadUrl;
//    }
//
////    /**
////     * 下载
////     */
////    public byte[] download(String targetUrl) {
////        //获取downloadUrl
////        String downloadUrl = getDownloadUrl(targetUrl);
////        return download(downloadUrl);
////    }
//    /**
//     * 通过发送http get 请求获取文件资源
//     * @param targetUrl
//     * @return
//     */
//    public byte[] download(String targetUrl) {
//        String downloadUrl = getDownloadUrl(targetUrl);
//        OkHttpClient client = new OkHttpClient();
//        Request req = new Request.Builder().url(downloadUrl).build();
//        okhttp3.Response resp = null;
//        try {
//            resp = client.newCall(req).execute();
//            if(resp.isSuccessful()) {
//                ResponseBody body = resp.body();
//                InputStream is = body.byteStream();
//                byte[] data = readInputStream(is);
//                return data;
//            }
//        } catch (IOException e) {
//        }
//        return null;
//    }
//
//    /**
//     * 读取字节输入流内容
//     * @param is
//     * @return
//     */
//    private static byte[] readInputStream(InputStream is) {
//        ByteArrayOutputStream writer = new ByteArrayOutputStream();
//        byte[] buff = new byte[1024 * 2];
//        int len = 0;
//        try {
//            while((len = is.read(buff)) != -1) {
//                writer.write(buff, 0, len);
//            }
//            is.close();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return writer.toByteArray();
//    }
//
//
//}
